<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml"
	  xmlns:v-bind="http://www.w3.org/1999/xhtml">

	<head>

		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>小K服务后台管理系统</title>
		<meta name="keywords" content="">
		<meta name="description" content="">

		<link rel="shortcut icon" href="../../../../static/favicon.ico" th:href="@{/favicon.ico}">

		<link rel="stylesheet" type="text/css" href="../../../../static/bootstrap/css/bootstrap.min.css" th:href="@{/bootstrap/css/bootstrap.min.css}" />
		<link rel="stylesheet" type="text/css" href="../../../../static/plugins/iCheck/custom.css" th:href="@{/plugins/iCheck/custom.css}" />
        <link rel="stylesheet" type="text/css" href="../../../../static/plugins/switchery/switchery.css" th:href="@{/plugins/switchery/switchery.css}" />
        <link rel="stylesheet" type="text/css" href="../../../../static/plugins/layui/css/layui.css" th:href="@{/plugins/layui/css/layui.css}" />
        <link rel="stylesheet" type="text/css" href="../../../../static/web/admin/css/font-awesome.css" th:href="@{/web/admin/css/font-awesome.css}" />
        <link rel="stylesheet" type="text/css" href="../../../../static/web/admin/css/animate.css" th:href="@{/web/admin/css/animate.css}" />
        <link rel="stylesheet" type="text/css" href="../../../../static/web/admin/css/style.css" th:href="@{/web/admin/css/style.css}" />

		<style type="text/css">
			table td,
			table th {
				text-align: center;
			}
		</style>
	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight" id="body">
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5>网站用户管理 <small>网站用户管理</small></h5>
						</div>
						<div class="ibox-content">
							<div class="row">
								<div class="col-sm-5 m-b-xs">

									<div class="btn-group" id="exampleToolbar" role="group">
										<button type="button" class="btn btn-outline btn-default" v-on:click="add">
                                        <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                                    </button>
										<button type="button" class="btn btn-outline btn-default" v-on:click="del(undefined)">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                    </button>
												<div class="btn-group">
													<button data-toggle="dropdown" class="btn btn-white dropdown-toggle">登录状态 <span class="caret"></span>
                                </button>
													<ul class="dropdown-menu">
														<li>
															<a href="javascript:void(0);" v-on:click="setLogin(false)">禁止登陆</a>
														</li>
														<li class="divider"></li>
														<li>
															<a href="javascript:void(0);" v-on:click="setLogin(true)">允许登录</a>
														</li>
													</ul>
												</div>
									</div>

								</div>
								<div class="col-sm-4 m-b-xs">
								</div>
								<div class="col-sm-3">
									<div class="input-group">
										<input type="text" v-model.trim="pageInfo.search" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-primary"  v-on:click="searchUser"> 搜索</button> </span>
									</div>
								</div>
							</div>
							<div>
								<table class="table table-hover table-bordered">
									<thead>
										<tr>
											<th style="width: 50px;"><input type="checkbox" class="i-checks" v-on:click="select" v-model="selectAll"></th>
											<th>昵称</th>
											<th>联系方式</th>
											<th>电子邮件</th>
											<th>实名认证</th>
											<th style="width: 50px;">操作</th>
										</tr>
									</thead>
									<tbody id="list">
										<tr v-for="(item, index) in list" v-bind:class="{warning:!item.verified}">
											<td>
												<input type="checkbox" v-bind:checked="item.select" v-bind:value="item.id" class="i-checks">
											</td>
											<td>{{item.stuId}}</td>
											<td>{{item.name}}</td>
											<td>{{item.phone}}</td>
											<td>{{item.email}}</td>
											<td>{{item.room}}</td>
											<td>
												<div class="btn-group">
													<button data-toggle="dropdown" class="btn btn-white dropdown-toggle">操作 <span class="caret"></span>
                                </button>
													<ul class="dropdown-menu">
                                                        <li>
                                                            <a href="javascript:void(0);" v-on:click="update(item)">修改用户信息</a>
                                                        </li>
                                                        <li>
                                                            <a href="javascript:void(0);" v-on:click="updatePassword(item)">修改用户密码</a>
                                                        </li>
														<li class="divider"></li>
														<li>
															<a href="javascript:void(0);" v-on:click="setLogin(false,item)">禁止登陆</a>
														</li>
														<li>
															<a href="javascript:void(0);" v-on:click="setLogin(true,item)">允许登录</a>
														</li>
														<li class="divider"></li>
														<li>
															<a href="javascript:void(0);" class="font-bold" v-on:click="del(item)">删除用户</a>
														</li>
													</ul>
												</div>
											</td>
										</tr>
										<tr v-if="!list || list.length == 0" style="text-align: center;"><td colspan="7">没有更多内容</td></tr>
									</tbody>
								</table>
							</div>
							<div id="page"></div>
						</div>
					</div>
				</div>

			</div>

		</div>

		<div id="winLayer" style="display: none;margin: 0;padding:0 20px;">
			<form class="form-horizontal m-t">
				<input type="hidden" v-model="info.id" />
				<div class="form-group">
					<label class="col-sm-3 control-label">学号</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" placeholder="学号" required="" aria-required="true" v-model="info.stuId" v-bind:disabled="info.id*1>0">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">姓名</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" placeholder="姓名" required="" aria-required="true" v-model="info.name">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">联系方式</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" required="" placeholder="联系方式" aria-required="true" v-model="info.phone">
					</div>
				</div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">电子邮件</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" required="" placeholder="电子邮件" aria-required="true" v-model="info.email">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">宿舍信息</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" required="" placeholder="宿舍信息" aria-required="true" v-model="info.room">
                    </div>
                </div>
			</form>
		</div>
		<script src="../../../../static/plugins/jquery.min.js" th:src="@{/plugins/jquery.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../static/bootstrap/js/bootstrap.min.js" th:src="@{/bootstrap/js/bootstrap.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../static/plugins/vuejs/vue.min.js" th:src="@{/plugins/vuejs/vue.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../static/plugins/layui/layui.js" th:src="@{/plugins/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../static/web/admin/js/content.js" th:src="@{/web/admin/js/content.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../static/plugins/switchery/switchery.js" th:src="@{/plugins/switchery/switchery.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../static/plugins/peity/jquery.peity.min.js" th:src="@{/plugins/peity/jquery.peity.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../static/plugins/iCheck/icheck.min.js" th:src="@{/plugins/iCheck/icheck.min.js}" type="text/javascript" charset="utf-8"></script>
		<script>
            layui.use(['layer', 'laypage', 'laydate'], function(){
                var layer = layui.layer //获得layer模块
                    ,laypage = layui.laypage //获得laypage模块
                    ,laydate = layui.laydate; //获得laydate模块
                //使用模块
                var win = new Vue({
                    el:"#winLayer",
                    data:{
                        info:{}
                    },
                    methods:{
                        showAdd:function(){
                            this.info={};
                            var addWin = layui.layer.open({
                                title: "添加学生信息",
                                type: 1,
                                area: ['400px', '450px'],
                                content: $("#winLayer"),
                                btn: ["添加", "取消"],
                                yes: function(index, layero) {
                                    var info = win.info;
                                    layui.layer.close(index);
                                    $.ajax({
                                        type: "post",
                                        data: info,
                                        url: AjaxUrl.admin.user.add,
                                        async: true,
                                        dataType: "json",
                                        success: function(data) {
                                            if(data.code === 0){
                                                app.loadPage(1);
                                            }else{
                                                layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                            }
                                        },
                                        error: function() {
                                            layui.layer.msg("加载错误");
                                        }
                                    });
                                }
                            });
                        },
                        showUpdate:function (item) {
                            this.info=item;
                            layui.layer.open({
                                title: "修改学生信息",
                                type: 1,
                                area: ['400px', '450px'],
                                content: $("#winLayer"),
                                btn: ["修改", "取消"],
                                yes: function(index, layero) {
                                    var info = win.info;
                                    layui.layer.close(index);
                                    $.ajax({
                                        type: "post",
                                        data: info,
                                        url: AjaxUrl.admin.user.update,
                                        async: true,
                                        dataType: "json",
                                        success: function(data) {
                                            if(data.code === 0){
                                                app.loadPage(1);
                                            }else{
                                                layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                            }
                                        },
                                        error: function() {
                                            layui.layer.msg("加载错误");
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
                var app = new Vue({
                    el: '#body',
                    data: {
                        selectAll: false,
                        list: [],
                        pageInfo:{
                            page:1,
                            search:""
                        }
                    },
                    methods: {
                        searchUser: function() {
                            this.loadPage(1);
                        },
                        add: function() {
                            win.showAdd();
                        },
                        update: function(item) {
                            win.showUpdate(item);
                        },
                        /*updateName:function (item) {
                            layui.layer.prompt({
                                formType: 0,
                                value: item.name,
                                title: '请输入姓名'
                            }, function(value, index, elem){
                                layui.layer.close(index);
                                $.ajax({
                                    type: "post",
                                    data: {id:item.id,name:value},
                                    url: AjaxUrl.admin.user.updateName,
                                    async: true,
                                    dataType: "json",
                                    success: function(data) {
                                        if(data.code === 0){
                                            app.loadPage(1);
                                        }else{
                                            layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                        }
                                    },
                                    error: function() {
                                        layui.layer.msg("加载错误");
                                    }
                                });
                            });
                        },
                        updatePhone:function (item) {
                            layui.layer.prompt({
                                formType: 0,
                                value: item.phone,
                                title: '请输入联系方式'
                            }, function(value, index, elem){
                                layui.layer.close(index);
                                $.ajax({
                                    type: "post",
                                    data: {id:item.id,phone:value},
                                    url: AjaxUrl.admin.user.updatePhone,
                                    async: true,
                                    dataType: "json",
                                    success: function(data) {
                                        if(data.code === 0){
                                            app.loadPage(1);
                                        }else{
                                            layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                        }
                                    },
                                    error: function() {
                                        layui.layer.msg("加载错误");
                                    }
                                });
                            });
                        },
                        updateEmail:function (item) {
                            layui.layer.prompt({
                                formType: 0,
                                value: item.email,
                                title: '请输入电子邮件'
                            }, function(value, index, elem){
                                layui.layer.close(index);
                                $.ajax({
                                    type: "post",
                                    data: {id:item.id,email:value},
                                    url: AjaxUrl.admin.user.updateEmail,
                                    async: true,
                                    dataType: "json",
                                    success: function(data) {
                                        if(data.code === 0){
                                            app.loadPage(1);
                                        }else{
                                            layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                        }
                                    },
                                    error: function() {
                                        layui.layer.msg("加载错误");
                                    }
                                });
                            });
                        },
                        updateRoom:function (item) {
                            layui.layer.prompt({
                                formType: 0,
                                value: item.room,
                                title: '请输入宿舍信息'
                            }, function(value, index, elem){
                                layui.layer.close(index);
                                $.ajax({
                                    type: "post",
                                    data: {id:item.id,room:value},
                                    url: AjaxUrl.admin.user.updateRoom,
                                    async: true,
                                    dataType: "json",
                                    success: function(data) {
                                        if(data.code === 0){
                                            app.loadPage(1);
                                        }else{
                                            layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                        }
                                    },
                                    error: function() {
                                        layui.layer.msg("加载错误");
                                    }
                                });
                            });
                        },*/
                        updatePassword:function (item) {
                            layui.layer.prompt({
                                formType: 1,
                                value: "",
                                title: '请输入新的密码'
                            }, function(value, index, elem){
                                layui.layer.close(index);
                                $.ajax({
                                    type: "post",
                                    data: {id:item.id,password:value},
                                    url: AjaxUrl.admin.user.updatePassword,
                                    async: true,
                                    dataType: "json",
                                    success: function(data) {
                                        if(data.code === 0){
                                            app.loadPage(1);
                                        }else{
                                            layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                        }
                                    },
                                    error: function() {
                                        layui.layer.msg("加载错误");
                                    }
                                });
                            });
                        },
                        setLogin:function (isLogin,item) {
                            var data = {id:[],isLogin:isLogin};
                            var names = [];
                            if (item === undefined) {
                                for(var i in this.list) {
                                    var item1 = this.list[i];
                                    if(item1.select) {
                                        data.id.push(item1.id);
                                        names.push(item1.name);
                                    }
                                }
                            }else {
                                data.id.push(item.id);
                                names.push(item.name);
                            }

                            if(names.length === 0) {layui.layer.msg("没有选择要操作的用户帐号", {time: 20000,btn: ['明白了']});return false;}
                            layui.layer.confirm('您确定要设置【' + names.join("、") + '】的登录状态为【'+isLogin+'】吗', {
                                btn: ['确定设置登录状态', '放弃吧，留着还有用'] //按钮
                            }, function() {
                                $.ajax({
                                    type: "post",
                                    data: data,
                                    url: AjaxUrl.admin.user.setLogin,
                                    async: true,
                                    dataType: "json",
                                    success: function(data) {
                                        if(data.code === 0){
                                            app.loadPage(1);
                                        }else{
                                            layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                        }
                                    },
                                    error: function() {
                                        layui.layer.msg("加载错误");
                                    }
                                });
                            });
                        },
                        del: function(item) {
                            var data = {id:[]};
                            var names = [];
                            if (item === undefined) {
                                for(var i in this.list) {
                                    var item1 = this.list[i];
                                    if(item1.select) {
                                        data.id.push(item1.id);
                                        names.push(item1.name);
                                    }
                                }
                            }else{
                                data.id.push(item.id);
                                names.push(item.name);
                            }
                            if(names.length === 0){layui.layer.msg("没有选择要删除的用户帐号", {time: 20000,btn: ['明白了']});return false;}
                            layui.layer.confirm('您确定要删除【' + names.join("、") + '】用户信息吗？删除用户后，用户的报修单和操作记录将一并删除', {
                                btn: ['确定删除用户', '不，我留着生孩子'] //按钮
                            }, function() {
                                layui.layer.prompt({
                                    formType: 1,
                                    value: "",
                                    title: '请验证当前用户密码'
                                }, function(value, index, elem){
                                    layui.layer.close(index);
                                    data.password = value;
                                    $.ajax({
                                        type: "post",
                                        data: data,
                                        url: AjaxUrl.admin.user.del,
                                        async: true,
                                        dataType: "json",
                                        success: function(data) {
                                            if(data.code === 0){
                                                app.loadPage(1);
                                            }else{
                                                layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                            }
                                        },
                                        error: function() {
                                            layui.layer.msg("加载错误");
                                        }
                                    });
                                });

                            });
                        },
                        select: function() {
                            for(var i = 0; i < this.list.length; i++) {
                                this.list[i].select = this.selectAll
                            }
                        },
                        loadPage: function(page) {
                            if(page === undefined) {
                                // 重新加载当前页面
                            }else if(page * 1 < 1) {
                                this.pageInfo.page=1;
                            }else {
                                this.pageInfo.page=page;
                            }
                            $.ajax({
                                type: "get",
                                data:app.pageInfo,
                                url: AjaxUrl.admin.user.list,
                                async: true,
                                dataType: "json",
                                success: function(data) {
                                    if (data.code === 0) {
                                        layui.layer.msg(data.msg);
                                        app.list = data.list;
                                        layui.laypage.render({
                                            elem: "page",
                                            count:data.count,
                                            limit:10,
                                            curr: data.pageCurr,
                                            groups: 10,
                                            jump: function(obj, first) {
                                                //得到了当前页，用于向服务端请求对应数据
                                                var curr = obj.curr;
                                                if(!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                                    app.loadPage(curr);
                                                }
                                            }
                                        });
                                    }else {
                                        layui.layer.msg(data.msg, {time: 20000, btn: ['明白了']});
                                    }
                                },
                                error:function () {
                                    layui.layer.msg("加载错误", {time: 5000, btn: ['明白了']});
                                }
                            });
                        }
                    }
                });
                app.loadPage(1);
            });
		</script>
	</body>

</html>